
<template>
  <div class="showCard">
    <div class="content">
      <div class="showSlot">
        <slot></slot>
      </div>
      <el-collapse-transition>
        <div v-show="flag">
          <CodeBlock :code="code" />
        </div>
      </el-collapse-transition>
      <div class="btn" @click="flag = !flag">
        <i :class="[
          { 'el-icon-caret-bottom': !flag },
          { 'el-icon-caret-top': flag },
        ]">{{ flag ? "隐藏代码" : "显示代码" }}</i>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import CodeBlock from './codeBlock';
defineProps({
  code: {
    type: String
  }
})
const flag = ref(false)
</script>

<style lang="stylus" scoped>
.showCard {
  text-align: left;
  background-color: #fff;

  .content {
    border: 1px solid #ebebeb;
    border-radius: 3px;
    margin-bottom: 0.2rem;
    .showSlot {
      padding: 0.2rem;
    }
    .btn {
      border-top: 1px solid #eaeefb;
      height: 0.44rem;
      line-height: 0.44rem;
      box-sizing: border-box;
      background-color: #fff;
      border-bottom-left-radius: 4px;
      border-bottom-right-radius: 4px;
      text-align: center;
      margin-top: -1px;
      color: #d3dce6;
      cursor: pointer;
      position: relative;
      font-size: 0.14rem;
      color: #409eff;
    }
  }
}
</style>
